from typing import List


class Solution:
    def fourSumCount(self, nums1: List[int], nums2: List[int],
                     nums3: List[int], nums4: List[int]) -> int:
        resNum = 0
        firstSum = {}
        for i in range(len(nums1)):
            for k in range(len(nums2)):
                firstSum[nums1[i] + nums2[k]] = firstSum.get(nums1[i] + nums2[k], 0) + 1

        for i in range(len(nums3)):
            for k in range(len(nums4)):
                resNum += firstSum.get(-1 * (nums3[i] + nums4[k]), 0)

        return resNum


print(Solution().fourSumCount([1, 2], [-2, -1], [-1, 2], [0, 2]))
